package com.wang.bootbuilder.controller;

import com.wang.bootbuilder.annotation.HasPermission;
import com.wang.bootbuilder.entity.param.UserParam;
import com.wang.bootbuilder.service.UserService;
import com.wang.bootbuilder.tools.JsonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage/user")
@Api(value = "/manage/user", description = "处理用户相关请求的controller")
public class UserController {

    @Autowired
    UserService userService;

    /*
    添加用户
     */
    @PostMapping("/add")
    public JsonResult addUser(@RequestBody @Validated UserParam param) {
        JsonResult jsonResult = userService.addUser(param);
        return jsonResult;
    }

    /*
    更新用户
     */
    @PostMapping("/update")
    public JsonResult updateUser(@RequestBody @Validated UserParam param) {
        JsonResult jsonResult = userService.updateUser(param);
        return jsonResult;
    }

    /*
    获取所有用户列表
     */
    @GetMapping("/list")
    @HasPermission("5")
    public JsonResult getUsers() {
        JsonResult jsonResult = userService.getUsers();
        return jsonResult;
    }

    /*
    删除指定用户
     */
    @PostMapping("/delete")
    public JsonResult deleteUser(@RequestBody UserParam param) {
        JsonResult jsonResult = userService.deleteUser(param.getId());
        return jsonResult;
    }

}
